package cn.iocoder.yudao.module.poppet.controller.admin.petinfo;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;



import cn.iocoder.yudao.module.poppet.controller.admin.petinfo.vo.*;
import cn.iocoder.yudao.module.poppet.dal.dataobject.petinfo.PetInfoDO;
import cn.iocoder.yudao.module.poppet.service.petinfo.PetInfoService;

import java.util.List;

@Tag(name = "管理后台 - 宠物档案")
@RestController
@RequestMapping("/poppet/pet-info")
@Validated
public class PetInfoController {

    @Resource
    private PetInfoService petInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建宠物档案")
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:create')")
    public CommonResult<Long> createPetInfo(@Valid @RequestBody PetInfoSaveReqVO createReqVO) {
        return success(petInfoService.createPetInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新宠物档案")
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:update')")
    public CommonResult<Boolean> updatePetInfo(@Valid @RequestBody PetInfoSaveReqVO updateReqVO) {
        petInfoService.updatePetInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除宠物档案")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:delete')")
    public CommonResult<Boolean> deletePetInfo(@RequestParam("id") Long id) {
        petInfoService.deletePetInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得宠物档案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:query')")
    public CommonResult<PetInfoRespVO> getPetInfo(@RequestParam("id") Long id) {
        PetInfoDO petInfo = petInfoService.getPetInfo(id);
        return success(BeanUtils.toBean(petInfo, PetInfoRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得宠物档案列表")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:query')")
    public CommonResult<List<PetInfoRespVO>> getPetList(@RequestParam("type") Integer type) {
        List<PetInfoDO> petInfo = petInfoService.getPetList(type);
        return success(BeanUtils.toBean(petInfo, PetInfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得宠物档案分页")
    @PreAuthorize("@ss.hasPermission('poppet:pet-info:query')")
    public CommonResult<PageResult<PetInfoRespVO>> getPetInfoPage(@Valid PetInfoPageReqVO pageReqVO) {
        PageResult<PetInfoDO> pageResult = petInfoService.getPetInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PetInfoRespVO.class));
    }

}